﻿//copyright © kaveh.shahbazian@gmail.com and http://www.codeplex.com/site/users/view/Cread 2010-2011 (see license.txt)
using System.Windows;
using System.Windows.Forms;
using System.IO;
using System.Windows.Media;

namespace Funtastic
{
    public partial class Options : Window
    {
        public Options()
        {
            InitializeComponent();

            _path.TextChanged += _path_TextChanged;
            Loaded += Options_Loaded;
        }

        void _path_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
        {
            if (Directory.Exists(_path.Text) && File.Exists(_path.Text + "\\Fsi.exe"))
                _borderPath.BorderBrush = new SolidColorBrush(Colors.Black);
            else
            {
                _borderPath.BorderBrush = new SolidColorBrush(Colors.Red);
            }
        }

        void Options_Loaded(object sender, RoutedEventArgs e)
        {
            _path.Text = Settings.FsPath;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // saving options
            Settings.FsPath = _path.Text;

            Close();
        }

        private void _choosepath_Click(object sender, RoutedEventArgs e)
        {
            var fbd = new FolderBrowserDialog();
            fbd.ShowNewFolderButton = false;
            fbd.Description = Properties.Resources.PrepareFsi_Open_folder_which_contains_Fsi;
            if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK && Directory.Exists(fbd.SelectedPath))
                _path.Text = fbd.SelectedPath;
            fbd.Dispose();
        }
    }
}